package com.five.system.service.impl;

import com.five.basic.service.impl.BaseServiceImpl;
import com.five.exception.BusinessException;
import com.five.pojo.User;
import com.five.system.mapper.UserMapper;
import com.five.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {
    @Autowired
    private UserMapper userMapper;


    /**
     * 根据登录信息id查询用户
     * @param loginInfoId
     * @return
     */
    @Override
    public User queryByLoginInfoId(Long loginInfoId) {
        if (loginInfoId == null){
            throw new BusinessException("loginfoId为空");
        }
        User user = userMapper.queryByLoginInfoId(loginInfoId);
        return user;
    }

    /**
     * 添加用户
     * @param user
     */
    @Override
    public void insertUser(User user) {
        if(user == null){
            throw new BusinessException("用户信息为空");
        }
        userMapper.add(user);
    }

    /**
     * 修改用户
     * @param user
     */
    @Override
    public void updateUser(User user) {
        if(user == null){
            throw new BusinessException("用户信息为空");
        }
        userMapper.update(user);
    }

    /**
     * 根据账号查询用户
     * @param account
     * @return
     */
    @Override
    public User queryByAccount(String account) {
        if (account == null || account.trim().length() == 0){
            throw new BusinessException("账号不能为空");
        }
        return userMapper.queryByAccount(account);
    }
}
